#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;

struct have {
    int points;
    int get;
    int lost;
};

struct team{
    string name;
    int points;
    int get;
    int lost;
};

int main() {
    int T;
    cin >> T;
    while (T--) {
        unordered_map<string, have> mm;
        for (int i = 0; i < 6; i++) {
            string name;
            cin >> name;
            cin >> mm[name].points >> mm[name].get >> mm[name].lost;
        }
        for (int i = 0; i < 3; i++) {
            string t1, t2;
            int g1, g2;
            cin >> t1 >> t2 >> g1 >> g2;
            if (g1 > g2) {
                mm[t1].points += 3;
            } else if (g1 < g2) {
                mm[t2].points += 3;
            } else {
                mm[t1].points += 1;
                mm[t2].points += 1;
            }
            mm[t1].get += g1;
            mm[t1].lost += g2;
            mm[t2].get += g2;
            mm[t2].lost += g1;
        }
        team teams[6];
        int cur=0;
        for(auto it : mm){
            teams[cur].name = it.first;
            teams[cur].points = it.second.points;
            teams[cur].get = it.second.get;
            teams[cur].lost = it.second.lost;
            cur++;
        }
        sort(teams, teams+6, [](team t1, team t2){
            if(t1.points != t2.points) return t1.points > t2.points;
            if(t1.get - t1.lost != t2.get - t2.lost) return (t1.get - t1.lost) > (t2.get - t2.lost);
            if(t1.get != t2.get) return t1.get > t2.get;
            return t1.name < t2.name;
        });
        for(int i=0;i<6;i++){
            cout << teams[i].name << " " << teams[i].points << " "
                << teams[i] .get << " " << teams[i].lost << endl;
        }
        cout << "END" << endl;
    }

    return 0;
}